home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / fswind.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  12KB  |  522 lines

  1. /***   [fswind.c]
  2. *
  3. *    ファイルセレクタウィンドウ 関連        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <jctype.h>
  14. #include "graph.h"
  15. #include "dos.h"
  16. #include "icn.h"
  17. #include "window.h"
  18. #include "mos.h"
  19. #include "dropdm.h"
  20. #include "fswind.h"
  21. #include "others.h"
  22. #include "optparse.h"
  23.  
  24. extern int    PAL_Black;
  25. extern unsigned char    RIN_dataBuf[303];
  26. static char    wmode;
  27. static char    (*flinf)[45];
  28. static struct cvars_t    cv;
  29.  
  30. static int    Getdrinfo(void);
  31. static int    mygetcd(char *);
  32. static void    FSW_Setfiles(get_f *);
  33.  
  34. void WIND_filesel_init(void) {
  35.     OPT_filew(&wmode, &cv.cap, &cv.sort);
  36. }
  37.  
  38. /***
  39. *    ファイル・セレクタ関数
  40. *        入力:    path   ファイル名格納用バッファ (85バイト必要)
  41. *                mode   0以外の時のときワイド型
  42. *                capital   0以外のとき大文字
  43. *                dirsort   0:ソートなし   1:種類別   2:名前順   3:作成日時順
  44. *        戻り値:    0:キャンセル   1:入力あり   -1:エラー
  45. ***/
  46. int WIND_filesel(const char *title, char *path) {
  47.     int        ret;
  48.     struct RECT    af1 = {
  49.         319, 259, 320, 260
  50.     };
  51.     
  52.     cv.title = title;
  53.     if (Getdrinfo()) {
  54.         WIND_error(1, NULL);
  55.         return -1;
  56.     }
  57.     wmode = !wmode;
  58.     do {
  59.         struct RECT    af2;
  60.         
  61.         MOS_disp(0);
  62.         EGB_cls(0);
  63.         MOS_disp(1);
  64.         if (wmode = !wmode) {
  65.             cv.drw = (cv.drinfo[0] + 10) / 11;
  66.             cv.wx = 0;
  67.             cv.wy = 40 + (424 - (356 + 20 * cv.drw)) / 2;
  68.             
  69.             af2.x1 = cv.wx;
  70.             af2.y1 = cv.wy;
  71.             af2.x2 = af2.x1 + 639;
  72.             af2.y2 = af2.y1 + 355 + 20 * cv.drw;
  73.             afterImage(&af1, &af2);
  74.             
  75.             ret = WIND_file_w(path, &cv);
  76.             
  77.             af1.x1 = cv.wx;
  78.             af1.y1 = cv.wy;
  79.             af1.x2 = af1.x1 + 639;
  80.             af1.y2 = af1.y1 + 355 + 20 * cv.drw;
  81.         } else {
  82.             cv.drw = (cv.drinfo[0] + 6) / 7;
  83.             cv.wx = (640 - 396) / 2;
  84.             cv.wy = 40 + (424 - (236 + 20 * cv.drw)) / 2;
  85.             
  86.             af2.x1 = cv.wx;
  87.             af2.y1 = cv.wy;
  88.             af2.x2 = af2.x1 + 395;
  89.             af2.y2 = af2.y1 + 235 + 20 * cv.drw;
  90.             afterImage(&af1, &af2);
  91.             
  92.             ret = WIND_file_n(path, &cv);
  93.             
  94.             af1.x1 = cv.wx;
  95.             af1.y1 = cv.wy;
  96.             af1.x2 = af1.x1 + 395;
  97.             af1.y2 = af1.y1 + 235 + 20 * cv.drw;
  98.         }
  99.     } while (ret == 2);
  100.     free(flinf);
  101.     flinf = NULL;
  102.     
  103.     if (ret == -1)    WIND_error(1, NULL);
  104.     
  105.     return ret;
  106. }
  107.  
  108. /* ドライブ接続情報 格納 */
  109. static int Getdrinfo(void) {
  110.     int                i, ii = 0;
  111.     int                ncd, scd;
  112.     union REGS        regs;
  113.     struct SREGS    sregs;
  114.     
  115.     regs.h.ah = 0x00;
  116.     if (nativetoreal(RIN_dataBuf, 200, &sregs.ds, ®s.x.di))
  117.         return -1;
  118.     int86x(0x8e, ®s, ®s, &sregs);
  119.     
  120.     for (i = 0; i < 16; i++) {
  121.         unsigned char    d;
  122.         
  123.         if ((d = RIN_dataBuf[0x30 + i * 2]) != 0xff) {
  124.             switch (d) {
  125.                 case 2:    d = 1;    break;
  126.                 case 3:    d = 3;    break;
  127.                 default:    d = 0;    break;
  128.             }
  129.             cv.drinfo[ii * 2 + 1] = 'A' + i;
  130.             cv.drinfo[ii++ * 2 + 2] = d;
  131.         }
  132.     }
  133.     
  134.     Get_cdexinf(&ncd, &scd);
  135.     for (i = 0; i < ncd; i++) {
  136.         cv.drinfo[ii * 2 + 1] = scd + 'A' + i;
  137.         cv.drinfo[ii * 2 + 2] = 2;
  138.         ii++;
  139.     }
  140.     
  141.     cv.drinfo[0] = ii;
  142.     return 0;
  143. }
  144.  
  145. /* ドライブ描画 */
  146. void FSW_Draw_drive(void) {
  147.     int        i = 0, xn;
  148.     int        x, y, xx, yy;
  149.     
  150.     xn = wmode ? 11 : 7;
  151.     yy = cv.wy + 29;
  152.     
  153.     for (y = 0; y < cv.drw; y++) {
  154.         xx = cv.wx + (wmode ? 12 : 14);
  155.         for (x = 0; x < xn; x++) {
  156.             char    buf[5] = " :";
  157.             
  158.             if (i >= cv.drinfo[0])
  159.                 break;
  160.             
  161.             buf[0] = cv.drinfo[i * 2 + 1];
  162.             if (!cv.cap)
  163.                 buf[0] = tolower(buf[0]);
  164.             EGB_str2(buf, xx, yy + 15, PAL_Black);
  165.             DrawButton(1, xx + 16, yy, xx + 44, yy + 15);
  166.             ICN_drive(cv.drinfo[i * 2 + 2], xx + 18, yy + 2);
  167.             
  168.             i++;
  169.             xx += wmode ? 57 : 53;
  170.         }
  171.         yy += 20;
  172.     }
  173. }
  174.  
  175. /* modeが0のときは, カレント・ディレクトリを読み込んで描画, それ以外のときは単に描画 */
  176. /* diroffはmode==0のときCont_pathと同じ */
  177. int FSW_Draw_path(int mode, int *diroff) {
  178.     int        xx, yy;
  179.     
  180.     xx = cv.wx + (wmode ? 250 : 6);
  181.     yy = cv.wy + 28 + 20 * cv.drw;
  182.     
  183.     MOS_disp(0);
  184.     EGB_boxf(xx, yy, xx + 383, yy + 19, 7, 7);
  185.     MOS_disp(1);
  186.     
  187.     if (mode == 0) {
  188.         if (mygetcd(cv.dirbuf))
  189.             return -1;
  190.         *diroff = Cont_path(cv.dirbuf, 46, cv.dirbuf2);
  191.     }
  192.     
  193.     MOS_disp(0);
  194.     EGB_str2(cv.dirbuf2, xx + 8, yy + 17, PAL_Black);
  195.     MOS_disp(1);
  196.     
  197.     return 0;
  198. }
  199.  
  200. /* カレントドライブとディレクトリをbufへ格納 戻り値はエラーの場合-1 */
  201. static int mygetcd(char *buf) {
  202.     int        ret;
  203.     
  204.     FSW_getdrive(buf);
  205.     strcat(buf, "\\");
  206.     if (Get_curdir(0, buf + 3)) {
  207.         buf[2] = 0;
  208.         ret = -1;
  209.     } else {
  210.         ret = 0;
  211.     }
  212.     if (!cv.cap)
  213.         strlow(0, (unsigned char *)buf);
  214.     
  215.     return ret;
  216. }
  217.  
  218. /* ファイル名を描画 mode 0:読み込んで描画   1:単に描画   2:ソートしなおして描画 */
  219. /*    filehd:先頭のファイル番号   gf:ファイル情報   戻り値:エラーのとき-1           */
  220. int FSW_Draw_file(int mode, int filehd, get_f *gf) {
  221.     int        i, xx, yy, g;
  222.     
  223.     xx = cv.wx + (wmode ? 250 : 6);
  224.     yy = cv.wy + 49 + 20 * cv.drw;
  225.     g = wmode ? 14 : 8;
  226.     
  227.     MOS_disp(0);
  228.     EGB_boxf(xx, yy, xx + 367, yy + g * 20 - 1, 7, 7);
  229.     MOS_disp(1);
  230.     if (mode == 0) {
  231.         int        i;
  232.         
  233.         if (Getfiles(cv.sort, gf, 0))
  234.             return -1;
  235.         if (!cv.cap) {
  236.             for (i = 0; i < gf->nfiles; i++)
  237.                 strlow(0, (gf->pbuf[filehd + i])->name);
  238.         }
  239.         free(flinf);
  240.         if ((flinf = malloc(45 * gf->nfiles)) == NULL)
  241.             return -1;
  242.         FSW_Setfiles(gf);
  243.     } else if (mode == 2) {
  244.         Getfiles(cv.sort, gf, 1);
  245.         FSW_Setfiles(gf);
  246.     }
  247.     
  248.     MOS_disp(0);
  249.     for (i = 0; i + filehd < gf->nfiles && i < g; i++)
  250.         FSW_Draw_file_sub(i, filehd, gf);
  251.     MOS_disp(1);
  252.     
  253.     return 0;
  254. }
  255.  
  256. /* ファイル名を描画 (1行だけ)                               */
  257. /*    line:行番号   filehd:先頭のファイル番号   gf:ファイル情報 */
  258. void FSW_Draw_file_sub(int line, int filehd, get_f *gf) {
  259.     int        x, y;
  260.     
  261.     x = cv.wx + (wmode ? 258 : 14);
  262.     y = cv.wy + 66 + 20 * cv.drw + line * 20;
  263.     
  264.     ICN_file(flinf[filehd + line][0], x, y - 15);
  265.     EGB_str3(flinf[filehd + line] + 1, x + 32, y, PAL_Black, 7);
  266. }
  267.  
  268. static void FSW_Setfiles(get_f *gf) {
  269.     int        line, i, yy, mm, dd;
  270.     char    buf_base[10], buf_ext[5];
  271.     files    **ptr;
  272.     
  273.     #define F(x)    (flinf[line] + (x) + 1)
  274.     for (line = 0; line < gf->nfiles; line++) {
  275.         ptr = gf->pbuf + line;
  276.         
  277.         flinf[line][0] = Split_fname((char *)(*ptr)->name, (*ptr)->attr, buf_base, buf_ext);
  278.         if ((*ptr)->attr & _A_SUBDIR) {
  279.             char    *p;
  280.             
  281.             sprintf(F(0), "<%s%s>", buf_base, buf_ext);
  282.             p = strchr(F(0), '\0');
  283.             for (i = 22 - strlen(F(0)); i > 0; i--)
  284.                 *(p++) = ' ';
  285.         } else {
  286.             sprintf(F(0), "%-8s%-4s  ", buf_base, buf_ext);
  287.             if ((*ptr)->sz <= 999999)
  288.                 sprintf(F(14), "%6d  ", (*ptr)->sz);
  289.             else
  290.                 sprintf(F(14), "FFFFFF  ");
  291.         }
  292.         
  293.         yy = (*ptr)->dt >> 9;
  294.         mm = (*ptr)->dt >> 5 & 0x0f;
  295.         dd = (*ptr)->dt & 0x1f;
  296.         sprintf(F(22), "%2d-%2d-%2d.%2s  ", 80 + yy, mm, dd, Getyoubi(yy, mm, dd));
  297.         sprintf(F(35), "%2d:%2d", (*ptr)->tm >> 11, (*ptr)->tm >> 5 & 0x3f);
  298.     }
  299.     #undef F(x)
  300. }
  301.  
  302. /* スクロール・バー描画   filehd:先頭ファイル番号   nfile:ファイル数 */
  303. void FSW_Draw_scrollB(int filehd, int nfile) {
  304.     int        xx, yy, u, l, bar;
  305.     struct sb_t    sb;
  306.     
  307.     xx = cv.wx + (wmode ? 619 : 375);
  308.     yy = cv.wy + 65 + 20 * cv.drw;
  309.     
  310.     bar = wmode ? 248 : 128;
  311.     sb.tl = nfile;    sb.lpp = (wmode ? 14 : 8);
  312.     sb.blen = bar;    sb.bml = 15;
  313.     SCRB_page(&sb, filehd, &u, &l);
  314.     
  315.     MOS_disp(0);
  316.     if (u > 0)
  317.         EGB_boxf(xx, yy, xx + 14, yy + u - 1, 6, 6);
  318.     DrawButton(0, xx, yy + u, xx + 14, yy + l);
  319.     if (l < bar - 1)
  320.         EGB_boxf(xx, yy + l + 1, xx + 14, yy + bar - 1, 6, 6);
  321.     MOS_disp(1);
  322. }
  323.  
  324. void FSW_Draw_volid(int mode) {
  325.     static char        volid[30];
  326.     
  327.     if (mode == 0) {
  328.         struct find_t    ft;
  329.         
  330.         sprintf(volid, "ボリュームラベルは");
  331.         if (_dos_findfirst("\\*.*", _A_VOLID, &ft)) {
  332.             strcat(volid, "ありません");
  333.         } else {
  334.             strcat(volid, " ");
  335.             if (strlen(ft.name) > 8) {
  336.                 strncat(volid, ft.name, 8);
  337.                 strcat(volid, ft.name + 9);
  338.             } else {
  339.                 strcat(volid, ft.name);
  340.             }
  341.         }
  342.         if (!cv.cap)
  343.             strlow(0, (unsigned char *)volid);
  344.     }
  345.     MOS_disp(0);
  346.     EGB_boxf(cv.wx + 9, cv.wy + 332 + 20 * cv.drw, cv.wx + 256, cv.wy + 347 + 20 * cv.drw, 7, 7);
  347.     EGB_str2(volid, cv.wx + 9, cv.wy + 347 + 20 * cv.drw, PAL_Black);
  348.     MOS_disp(1);
  349. }
  350.  
  351. /* ディスク・スペース描画   mode 0:読み込んで描画   1:単に描画 */
  352. int FSW_Draw_diskfree(int mode) {
  353.     int        xx, yy;
  354.     char    buf[40];
  355.     struct diskfree_t    diskf;
  356.     static unsigned long    bytes;
  357.     
  358.     xx = cv.wx + (wmode ? 257 : 11);
  359.     yy = cv.wy + (wmode ? 347 : 227) + 20 * cv.drw;
  360.     
  361.     MOS_disp(0);
  362.     EGB_boxf(xx, yy - 15, xx + 255, yy, 7, 7);
  363.     MOS_disp(1);
  364.     if (mode == 0) {
  365.         if (_dos_getdiskfree(0, &diskf))
  366.             return -1;
  367.         bytes = diskf.avail_clusters * diskf.sectors_per_cluster * diskf.bytes_per_sector;
  368.     }
  369.     
  370.     if (bytes <= 999999999)
  371.         Konma(bytes, buf);
  372.     else
  373.         sprintf(buf, "FFFFFFFFFFF");
  374.     strcpy(buf + 11, " バイトが使用可能です");
  375.     MOS_disp(0);
  376.     EGB_str2(buf, xx, yy, PAL_Black);
  377.     MOS_disp(1);
  378.     
  379.     return 0;
  380. }
  381.  
  382. /* ソート・オプション用関数  戻り値が0以外の時, *yへ結果代入 */
  383. int FSW_opt2(int *x, int *y) {
  384.     int        i;
  385.     struct dropdm_t    dp;
  386.     struct menu_t    m[1];
  387.     const char    *n[5];
  388.     static char    nstr[][20] = {
  389.         "   ソートなし ",
  390.         "   種  類  別 ",
  391.         "   名  前  順 ",
  392.         "   作成日時順 "
  393.     };
  394.     char    mask[] = {
  395.         0, 0, 0, 0
  396.     };
  397.     
  398.     m[0].xt = cv.wx + (wmode ? 593 : 349);
  399.     m[0].wt = 20;
  400.     m[0].xm = cv.wx + (wmode ? 547 : 303);
  401.     m[0].wm = 14;
  402.     if (m[0].xm + m[0].wm * 8 > 639)
  403.         m[0].xm = 639 - m[0].wm * 8;
  404.     
  405.     for (i = 0; i < 4; i++) {
  406.         strncpy(nstr[i] + 1, i == cv.sort ? "※" : "  ", 2);
  407.         n[i] = nstr[i];
  408.     }
  409.     n[4] = NULL;
  410.     m[0].name = n;
  411.     m[0].mask = mask;
  412.     
  413.     dp.ntitle = 1;
  414.     dp.yt1 = cv.wy + 6;
  415.     dp.yt2 = dp.yt1 + 19;
  416.     dp.ym = dp.yt1 + 26;
  417.     dp.m = m;
  418.     dp.shadow = 0;
  419.     
  420.     return DRPDM_main(x, y, &dp);
  421. }
  422.  
  423. /* 終了ボタン 関数   戻り値:ボタンが押された場合1 */
  424. int FSW_end(void) {
  425.     return Button(cv.wx + 6, cv.wy + 6, cv.wx + 25, cv.wy + 25);
  426. }
  427.  
  428. /* ウインドウ切り換えボタン 関数   戻り値:ボタンが押された場合1 */
  429. int FSW_opt1(void) {
  430.     int        xx;
  431.     
  432.     xx = cv.wx + (wmode ? 614 : 370);
  433.     
  434.     return Button(xx, cv.wy + 6, xx + 19, cv.wy + 25);
  435. }
  436.  
  437. void FSW_Draw_tree(int treehd, int col, struct dirtree_t *dt, int cd) {
  438.     int        y;
  439.     
  440.     MOS_disp(0);
  441.     EGB_boxf(cv.wx + 7, cv.wy + 30 + 20 * cv.drw, cv.wx + 230, cv.wy + 309 + 20 * cv.drw, 7, 7);
  442.     MOS_disp(1);
  443.     FSW_Draw_trscrlB(0, treehd, dt->numd, col, dt->numc);
  444.     FSW_Draw_trscrlB(1, treehd, dt->numd, col, dt->numc);
  445.     MOS_disp(0);
  446.     for (y = 0; y + treehd < dt->numd && y < 14; y++)
  447.         FSW_Draw_tree_line(treehd, col, y, dt, cd);
  448.     MOS_disp(1);
  449. }
  450.  
  451. void FSW_Draw_tree_line(int treehd, int col, int line, struct dirtree_t *dt, int cd) {
  452.     int        x, xx, yy, i;
  453.     unsigned char    branch[40];
  454.     
  455.     EGB_view(cv.wx + 7, cv.wy + 30 + 20 * cv.drw, cv.wx + 230, cv.wy + 309 + 20 * cv.drw);
  456.     x = cv.wx + 7 - 32 * col;
  457.     
  458.     TR_branch(1, branch, dt->tr[treehd + line].branch);
  459.     for (i = 0; i < dt->tr[treehd + line].nest - 1; i++) {
  460.         if (branch[i])
  461.             EGB_line(x + 24 + 32 * i, cv.wy + 30 + (line + cv.drw) * 20, x + 24 + 32 * i, cv.wy + 49 + (line + cv.drw) * 20, PAL_Black);
  462.     }
  463.     xx = x + 32 * dt->tr[treehd + line].nest;
  464.     yy = cv.wy + 47 + (line + cv.drw) * 20;
  465.     if (treehd + line != 0) {
  466.         if (dt->tr[treehd + line].dirn == 0xffff)
  467.             EGB_line(xx - 8, yy - 17, xx - 8, yy - 7, PAL_Black);
  468.         else
  469.             EGB_line(xx - 8, yy - 17, xx - 8, yy + 2, PAL_Black);
  470.         EGB_line(xx - 8, yy - 7, xx - 1, yy - 7, PAL_Black);
  471.     }
  472.     ICN_file(1, xx, yy - 15);
  473.     EGB_str3(dt->tr[treehd + line].name, xx + 32, yy, PAL_Black, 7);
  474.     if (treehd + line == cd)
  475.         EGB_rev(0, xx, yy - 17, xx + (4 + strlen(dt->tr[cd].name)) * 8 - 1, yy + 2);
  476.     EGB_view(0, 0, 1023, 511);
  477. }
  478.  
  479. void FSW_getdrive(char *buf) {
  480.     unsigned    dr;
  481.     
  482.     strcpy(buf, "A:");
  483.     _dos_getdrive(&dr);
  484.     buf[0] += dr - 1;
  485.     if (!cv.cap)
  486.         strlow(0, (unsigned char *)buf);
  487. }
  488.  
  489. /* ツリー・スクロール・バー描画 */
  490. void FSW_Draw_trscrlB(int hv, int trhd, int numd, int col, int numc) {
  491.     int        xx, yy, u, l;
  492.     struct sb_t    sb;
  493.     
  494.     MOS_disp(0);
  495.     if (hv) {
  496.         sb.tl = numd;    sb.lpp = 14;
  497.         sb.blen = 253;    sb.bml = 15;
  498.         SCRB_page(&sb, trhd, &u, &l);
  499.         
  500.         xx = cv.wx + 234;
  501.         yy = cv.wy + 44 + 20 * cv.drw;
  502.         if (u > 0)
  503.             EGB_boxf(xx, yy, xx + 14, yy + u - 1, 6, 6);
  504.         DrawButton(0, xx, yy + u, xx + 14, yy + l);
  505.         if (l < 252)
  506.             EGB_boxf(xx, yy + l + 1, xx + 14, yy + 252, 6, 6);
  507.     } else {
  508.         sb.tl = numc + 3;    sb.lpp = 7;
  509.         sb.blen = 195;        sb.bml = 15;
  510.         SCRB_page(&sb, col, &u, &l);
  511.         
  512.         xx = cv.wx + 22;
  513.         yy = cv.wy + 314 + 20 * cv.drw;
  514.         if (u > 0)
  515.             EGB_boxf(xx, yy, xx + u - 1, yy + 14, 6, 6);
  516.         DrawButton(0, xx + u, yy, xx + l, yy + 14);
  517.         if (l < 194)
  518.             EGB_boxf(xx + l + 1, yy, xx + 194, yy + 14, 6, 6);
  519.     }
  520.     MOS_disp(1);
  521. }
  522.